package io.jt808.controller;

import io.jt808.proto.Wrapper;
import io.jt808.proto.WrapperHeader;
import io.jt808.proto.cmd.JT8103;
import io.jt808.proto.req.JT0002;
import io.jt808.proto.rsp.JT8001;
import io.jt808.proto.rsp.JT8100;
import io.norland.annotations.ReqController;
import io.norland.annotations.ReqMapping;
import io.norland.proto.AbstractWrapper;
import io.norland.response.ActionAndModel;
import io.norland.service.Command;
import io.norland.service.Function;
import io.norland.service.QueueService;
import io.norland.service.ScheduledService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

/**
 * 测试发送要下达的指令
 */
@ReqController
public class TestController implements Serializable {
    @Autowired
    private QueueService executorService;
    @Autowired
    private ScheduledService scheduledExecutorService;

    @ReqMapping("8103")
    public ActionAndModel solve8103(WrapperHeader header, JT8103 content) {
//        Wrapper wp = (Wrapper) wrapper;
//        Object content = wp.getMessageContents();
//        JT8103 jt0002 = (JT8103) content;
        WrapperHeader header1=header;
        System.out.println(header1.getSimId());
        executorService.push(new Function() {
            @Override
            public void apply() {
                System.out.println("xxxxx");
            }
        });
        Command command = new Command();
        command.setTerminalSerialNo("016800024230");
        JT8001 jt8001_1 = new JT8001();
        jt8001_1.setResponseMessageId(1);
        jt8001_1.setResponseMessageSerialNo((short) 2);
        jt8001_1.setResponseResult((byte) 0x0001);
        command.setCmdData(jt8001_1);
        scheduledExecutorService.push(command);
        JT8001 jt8001 = new JT8001();
        jt8001.setResponseMessageSerialNo((short) 1);
        jt8001.setResponseMessageId(1);
        jt8001.setResponseResult((byte) 0x01);
        return ActionAndModel.responseModel(jt8001);
    }

    @ReqMapping("0002")
    public ActionAndModel solveABCD(WrapperHeader header,
                                    String serialNo,
                                    String protoName,
                                    JT0002 jt0002) {
        executorService.push(new Function() {
            @Override
            public void apply() {
                System.out.println(jt0002.toString());
            }
        });
        Command command = new Command();
        command.setTerminalSerialNo("016800024230");
        JT8001 jt8001 = new JT8001();
        jt8001.setResponseMessageId(1);
        jt8001.setResponseMessageSerialNo((short) 2);
        jt8001.setResponseResult((byte) 0x0001);
        command.setCmdData(jt8001);
        scheduledExecutorService.push(command);
        JT8100 jt8100 = new JT8100();
        jt8100.setResponseMessageSerialNo((short) 1);
        jt8100.setResult((byte) 0x00);
        jt8100.setAuthenticationCode("abc");
        return ActionAndModel.responseModel(jt8100);
    }
}
